package com.youlai.boot.modules.game.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.boot.modules.game.mapper.GameTagMapper;
import com.youlai.boot.modules.game.model.entity.GameTag;
import com.youlai.boot.modules.game.model.form.GameTagForm;
import com.youlai.boot.modules.game.service.GameTagService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 游戏标签服务实现类
 *
 * @author 有来技术团队
 */
@Service
@RequiredArgsConstructor
public class GameTagServiceImpl extends ServiceImpl<GameTagMapper, GameTag> implements GameTagService {
    
    private final GameTagMapper gameTagMapper;

    @Override
    public Page<GameTag> getTagPage(Integer pageNum, Integer pageSize, String keywords) {
        LambdaQueryWrapper<GameTag> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(keywords)) {
            queryWrapper.like(GameTag::getName, keywords);
        }
        queryWrapper.orderByAsc(GameTag::getSort);

        return page(new Page<>(pageNum, pageSize), queryWrapper);
    }

    @Override
    public List<GameTag> getAllTags() {
        LambdaQueryWrapper<GameTag> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByAsc(GameTag::getSort);
        return list(queryWrapper);
    }

    @Override
    public GameTag getTagById(Long id) {
        return getById(id);
    }

    @Override
    public List<GameTag> getTagsByGameId(Long gameId) {
        return gameTagMapper.getTagsByGameId(gameId);
    }

    @Override
    public Long addTag(GameTagForm formData) {
        GameTag entity = new GameTag();
        entity.setName(formData.getName());
        entity.setSort(formData.getSort());

        save(entity);
        return entity.getId();
    }

    @Override
    public boolean updateTag(Long id, GameTagForm formData) {
        GameTag entity = getById(id);
        if (entity == null) {
            return false;
        }

        entity.setName(formData.getName());
        entity.setSort(formData.getSort());

        return updateById(entity);
    }

    @Override
    public boolean deleteTags(List<Long> ids) {
        return removeByIds(ids);
    }
} 